﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace NFinalCommand
{
    public partial class frmInputFunction : Form
    {
        public frmInputFunction(Microsoft.VisualStudio.Text.Editor.IWpfTextView textView,int position)
        {
            InitializeComponent();
            this.textView = textView;
            this.position = position;
        }
        public static string methodName;
        private Microsoft.VisualStudio.Text.Editor.IWpfTextView textView;
        private int position;
        private void button1_Click(object sender, EventArgs e)
        {
            methodName = txtActionName.Text;
            Regex regex = new Regex("[_a-zA-Z][_a-zA-Z0-9]*");
            if (regex.IsMatch(methodName))
            {
                textView.TextBuffer.Insert(position,
                        $"\r\n\t\tpublic ActionResult {methodName}()\r\n\t\t{{\r\n\t\t\t\r\n\t\t}}");

            }
            else
            {
                MessageBox.Show("非法的变量名");
            }
            this.Close();
        }
    }
}
